var list = "#left-sidebar .category-list > ul";
var old_list;
$(function(){
if($('.gallery').length > 0 ) {
list = "#left-sidebar .widget-content > ul";
}
//mailing list
$("#mailing-list-subscribe-full").pkdDataSignup();
//sidebar
$("#sidebar-subscribe").pkdDataSignup();
$("#sidebar-search-refine-inner").mmenu({
position : "right",
subtitle_text: "Back",
zposition : ""
}, {
clone : true,
pageSelector: '#outer-page-wrapper',
bootstrap_compat : false,
bootstrap_classes: 'visible-xs hidden-xs',
panelClass: 'refine-panel',
isMenu: false,
pageNodetype: 'ul',
panelNodetype: 'ul',
subnavLockingEnable: false
});
//add touch ability to home carousel
if($(".carousel-inner").length > 0) {
//Enable carousel swiping
$(".carousel-inner").swipe( {
swipeLeft:function(event, direction, distance, duration, fingerCount) {
$(this).parent().carousel('next');
},
swipeRight: function() {
$(this).parent().carousel('prev');
},
threshold:55
});
}
//search results
// Enable onchange event on results view buttons & sortby
if($("#advSearchResultsView").length > 0) {
$('.viewRadio').change(function(){
$("#advSearchResultsView").submit();
});
}
if($('.gallery-sort-tools').length > 0) {
$('.gallery-sort-tools select').on('change', function(){
$(this).closest("form").submit();
});
}
//automatically expand category if category-list-open is present
$(".article-level-2 a.category-list-open").expandCategory(false);
//automatically expand category if category-list-open is present
$(".browse a.open-modal").expandCategory(true);
// Sidebar Category
// if($('.widget-category-list').length > 0) {
// $('.widget-category-list a').each(function(index) {
// //console.log($('span', this ).html());
// var arr = ['Varia','Periods','Themes'];
// var text = $('span', this ).html();
// if(jQuery.inArray(text,arr) != -1) {
// $( this ).click(function(e) {
// e.preventDefault();
// });
// }
// });
// }
//nav bar
// Initialize mobile menu
$("#navbar").mmenu({
position : "left",
subtitle_text: "Back",
zposition : "",
header: { add: true, content: '
' }
}, {
clone : true,
pageSelector: '#outer-page-wrapper',
bootstrap_compat : true,
bootstrap_classes: 'visible-xs'
});
$('#navbar-container').affix({
offset: {
top: $('#navbar-container').offset().top
}
});
$(window).on('scroll resize', function(event){
if($('#navbar-container').hasClass('affix')) {
$('body').addClass('navbar-affixed');
} else {
$('body').removeClass('navbar-affixed');
}
if(event.type == 'resize' && !$('body').hasClass('navbar-affixed'))
$('#navbar-container').data('bs.affix').options.offset = $('#navbar-container').offset().top;
});
// Superfish Dropdown
var navmenu = $('.nav').superfish({
//cssArrows: false
});
// COntact Forms
$("#contact-form").pkdDataForm();
$(window).on('resize', $.debounce(300, false, function(){
valign_carousel_images();
}));
$(".book-binding-icon a, .digitized-treasure-icon a").tooltip({html:true});
$(".nav-alt-link-bottom a").tooltip();
if($('#gallery').length > 0) {
var $gallery = $('#gallery');
var gallery_options = {
delegate: 'a.gallery-img',
type: 'image',
zoom: {
enabled: true,
opener: function (openerElement) {
//if the opener element is an image than use that to zoom
//else if there is no image inside the openerElement than find the image up a couple parents(used for detail page)
return (openerElement.is('img') ? openerElement : (openerElement.find('img').length > 0 ? openerElement.find('img') : openerElement.parent().parent().find('img')));
}
},
gallery: {
enabled: true
},
image: {
markup: '
'
},
callbacks: {
open: function () {
$self = this;
if ($self.wrap.find('.mfp-figure').css('position') != 'static') {
boxed_enabled = true;
}
$img = $self.wrap.find('.mfp-img');
$self.wrap.on('click', '.mfp-enlarge-link', function () {
$self.wrap.toggleClass('mfp-enlarged');
if ($self.wrap.hasClass('mfp-enlarged')) {
last_max_height = $img.css('max-height');
$img.css('max-height', 'none');
} else {
$img.css('max-height', last_max_height);
}
});
},
beforeClose: function () {
if (enlarge_enabled) {
this.wrap.off('click', '.mfp-enlarge-link');
this.wrap.removeClass('mfp-enlarged');
}
},
change: function () {
if (boxed_enabled) {
$.magnificPopup.instance.resizeImage.call(this);
}
/*var magnificPopup = $.magnificPopup.instance;
if(magnificPopup.index + 1 == magnificPopup.items.length) {
$("html, body").animate({scrollTop: $gallery.offset().top + $gallery.height()}, function(){
magnificPopup.close();
setTimeout(function(){
magnificPopup.open(gallery_options, magnificPopup.index);
}, 500);
});
}*/
//magnificPopup.goTo(1);
},
afterClose: function(){
//var magnificPopup = $.magnificPopup.instance;
//magnificPopup.open(gallery_options, magnificPopup.index);
},
imageLoadComplete: function () {
$self = this;
if (boxed_enabled) {
$.magnificPopup.instance.resizeImage.call(this);
}
if ($self.wrap.find('.mfp-enlarge').is(':visible')) {
enlarge_enabled = true;
}
if (enlarge_enabled) {
$self.wrap.removeClass('mfp-enlarged');
$img = $self.wrap.find('.mfp-img');
var img_size = $img.real_size();
if (img_size.width <= $img.width()) {
$self.wrap.find(".mfp-enlarge").hide();
} else {
$self.wrap.find(".mfp-enlarge").show();
}
}
}
}
};
$thumbnail = $gallery.find('.thumbnail');
if( $thumbnail.length > 0 ) {
$('.gallery #main-content').magnificPopup(gallery_options);
$("#gallery").on('click', '.widget-image', function(){
$("#link_" + $(this).attr("id")).trigger('click');
});
}
$gallery.jscroll({
loadingHtml: ' Loading...',
//padding: 20,
nextSelector: 'li.page_next a',
contentSelector: '.gallery-wrapper',
callback: function(){
//$('.lightbox').magnificPopup();
}
});
/*var $nav_featured = $('.nav-submenu-featured');
if($nav_featured.find('.active').length > 0 || $nav_featured.hasClass('active')) {
$nav_featured.find('ul').css('display', 'block');
}*/
}
if($('.open-related-books').length > 0 && $('#lyr-related-books').length > 0) {
modals.related_books = $('#lyr-related-books');
$('.open-related-books').on('click', function(){
modals.related_books.modal('show');
});
}
// custom css override expression for a case-insensitive contains()
jQuery.expr[":"].contains = jQuery.expr.createPseudo(function (arg) {
return function (elem) {
return jQuery(elem).text().toUpperCase().indexOf(arg.toUpperCase()) >= 0;
};
});
if($(list).length > 0) {
$("#filter-input").keyup(function () {
setTimeout(function(){
//reset filter classes anytime this changes
$('#left-sidebar').find('.filter-show').removeClass('filter-show');
$('#left-sidebar').find('.filter-hide').removeClass('filter-hide');
// the id of the filtered list
// the searched value
var filter = $("#filter-input").val();
//if we have a filter
//if the filter is greater than 1
if (filter && filter.length > 1) {
//then lets search
//set serach filter
search_filter = filter;
// search function for all children
search_child();
check_for_empty_results();
} else {
//we have no search filter
//reset serach filter to empty
search_filter = '';
//if we have search tokens
if(search_tokens.length > 0) {
//perform the search without a filter
search_child();
check_for_empty_results();
} else {
//no search tokens then reset to search
reset_gallery_search();
}
}
}, 700);
});
}
/* Filters Setup */
$('.token-form-control')
.on('tokenfield:createtoken', createtoken_callback)
.on('tokenfield:createdtoken', createdtoken_callback)
.on('tokenfield:removedtoken', removedtoken_callback)
.tokenfield({
autocomplete: {
source: function( request, response ) {
//get level from the data on our original input
var level = $('.token-input:focus').parent().find('.token-form-control').data('level');
var re = $.ui.autocomplete.escapeRegex(request.term);
var matcher = new RegExp(re, "i");
response($.grep(($.map(gallery_levels[level], function (v, i) {
var text = v.label,
children = v.children,
id = v.value;
return {
label: text,
value: text,
id: id,
children: children
};
})), function (item) {
return matcher.test(normalize(item.label));
}));
},
delay: 0/*,
select: function(event,ui) {
$("#left-sidebar").addClass('loading');
}*/
},
showAutocompleteOnFocus: false
});
$("#filters").on('click', '.tokenfield', function(){
$(this).find('.token-input').trigger( "focus" );
// Pass empty string as value to search for, displaying all results
$(this).find('.token-input').autocomplete( "search", "" );
});
$filters = $("#filters");
$("#left-sidebar").on('click', '#open-filters', function(){
if($filters.is(":visible")) {
$filters.hide();
$(this).html('Gallery Filters ');
} else {
$filters.show();
$(this).html('Hide Gallery Filters ');
}
});
$("#left-sidebar").on('click', '#clear-filters', function(){
$("#token-field-L1").tokenfield('setTokens','');
$("#token-field-L2").tokenfield('setTokens','');
$("#token-field-L3").tokenfield('setTokens','');
search_tokens = new Array();
if( search_filter != '' ) {
$('#left-sidebar').find('.token-show').removeClass('token-show');
$('#left-sidebar').find('.token-hide').removeClass('token-hide');
search_child();
check_for_empty_results();
} else {
reset_gallery_search();
}
});
$('.btn-toggle-sold').on('change', function(){
$("#search-toggle-sold").submit();
});
// Reset currency container between modal loads on results pages
var $currencies_modal = $('#currencies');
$currencies_modal.on('hidden.bs.modal', function () {
$(this).data('bs.modal', null);
});
$('.currency-modal-open').on('click', function(){
var href = $(this).data('href');
$currencies_modal.load(href);
$currencies_modal.modal('show');
});
});
$(window).load(function(){
if($(".carousel-inner").length > 0) {
valign_carousel_images();
}
init_gallery_sidebar();
});